import {
  getCompanyInfoByIdApi,
  getRolesListApi,
  getRoleById
} from '@/api/settings'
import defaultSettings from '@/settings'

const { showSettings, fixedHeader, sidebarLogo } = defaultSettings
export default {
  namespaced: true,
  state: {
    showSettings: showSettings,
    fixedHeader: fixedHeader,
    sidebarLogo: sidebarLogo,
    companyfForm: {},
    tableData: [],
    showDialog: false,
    total: 0,
    flag: true,
    roleInfo: {}
  },
  mutations: {
    CHANGE_SETTING: (state, { key, value }) => {
      // eslint-disable-next-line no-prototype-builtins
      if (state.hasOwnProperty(key)) {
        state[key] = value
      }
    },
    getCompanyInfo(state, companyfForm) {
      state.companyfForm = companyfForm
    },
    getInfo(state, data) {
      // console.log(total)
      state.tableData = data.rows
      state.total = data.total
    },
    changeDialog(state) {
      state.showDialog = !state.showDialog
    },
    flag(state, flag) {
      state.flag = flag
    },
    roleInfo(state, roleInfo) {
      state.roleInfo = roleInfo
    }
  },
  actions: {
    changeSetting({ commit }, data) {
      commit('CHANGE_SETTING', data)
    },
    async getCompanyInfo(context, id) {
      const res = await getCompanyInfoByIdApi(id)
      context.commit('getCompanyInfo', res.data)
    },
    /* 获取角色列表 */
    async getRoles(context, paramsObj) {
      const res = await getRolesListApi(paramsObj)
      context.commit('getInfo', res.data)
    },
    async getRolesById(context, id) {
      const res = await getRoleById(id)
      context.commit('roleInfo', res.data)
    }
  }
}

// import defaultSettings from '@/settings'

// const { showSettings, fixedHeader, sidebarLogo } = defaultSettings
// const state = {
//   showSettings: showSettings,
//   fixedHeader: fixedHeader,
//   sidebarLogo: sidebarLogo
// }

// const mutations = {
//   CHANGE_SETTING: (state, { key, value }) => {
//     // eslint-disable-next-line no-prototype-builtins
//     if (state.hasOwnProperty(key)) {
//       state[key] = value
//     }
//   }
// }

// const actions = {
//   changeSetting({ commit }, data) {
//     commit('CHANGE_SETTING', data)
//   }
// }

// export default {
//   namespaced: true,
//   state,
//   mutations,
//   actions
// }
